package com.system.userconsumer.controller;

import com.system.userconsumer.domain.Address;
import com.system.userconsumer.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author Lisiyu
 * date 2022/10/19 20:03
 * version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    private RestTemplate restTemplate;
    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/info/{id}")
    public User findById(@PathVariable Integer id){
        User user = new User();
        user.setId(id);
        user.setName("lsy");
        //需要地址信息，找到地址的程序获取
        Address address = restTemplate.getForObject("http://ADDRESSPROVIDEREUREKA04/address/info/" + id, Address.class);
        user.setAddress(address);
        return user;

    }
}
